<?php

namespace App\Http\Controllers\Main;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

use App\Model\Service;
use App\Model\ServiceCategory;

class ServiceController extends Controller
{
    //
    public function serviceList($cid) {
        $slist = Service::select('id','create_time','title','picture')->where('category_id',$cid)->where('status',1)->orderBy('create_time','desc')->paginate(9);
        foreach ($slist as $s => $value) {
            $slist[$s]['create'] = substr($value['create_time'],0,10);
        }
//        dump($slist);
        return view('main.service.list',compact('slist','cid'));
    }

    public function detail($id) {
        $data = Service::whereId($id)->first();
        $time = substr($data->create_time,0,10);
        $t = explode('-',$time);
        $list = Service::select('id','title')->where('category_id',$data->category_id)->where('id','!=',$data->id)->where('recomm',1)->where('status',1)->orderBy('create_time','desc')->get();
        return view('main.service.detail',compact('data','t','list'));
    }
}
